<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="jxl.*" %>
<%@ page import="jxl.write.*" %>
<% 
	request.setCharacterEncoding("UTF-8");
	String conName = request.getParameter("conName").trim();
	String conClass = request.getParameter("conClass").trim();;
	String time = request.getParameter("time").trim();
	String money = request.getParameter("money").trim();
	Calendar cal = Calendar.getInstance();
	cal.set(Integer.parseInt(time.split("/")[0]),Integer.parseInt(time.split("/")[1])-1,Integer.parseInt(time.split("/")[2]));
	Date date = cal.getTime();
	SimpleDateFormat datef = new SimpleDateFormat("yyyy年MM月dd日");
	time = datef.format(date).toString();
	File fileName = new File("E:/java/conform.xls");
	try{
		if(!fileName.exists()){
			WritableWorkbook workbook  =  Workbook.createWorkbook (fileName);
			WritableSheet sheettemp = workbook.createSheet("sheet1", 0);
			Label label = new Label(0,0,"消费名称");
			sheettemp.addCell(label);
			label = new Label(1,0,"消费种类");
			sheettemp.addCell(label);
			label = new Label(2,0,"消费时间");
			sheettemp.addCell(label);
			label = new Label(3,0,"消费金额");
			sheettemp.addCell(label);
			workbook.write();
			workbook.close();
		}
		Workbook book = Workbook.getWorkbook(fileName);
		Sheet sheet = book.getSheet(0); 
		int len = sheet.getRows();
		String tempstr = null;
		for(int i=0;i<len;i++){
			tempstr = sheet.getCell(0, i).getContents();
			if(conName.equals(tempstr) && time.equals(tempstr)){
				out.print("<a href='#########'>今天已经输入消费记录，如要修改消费信息，请修改！</a>");
				return ;
			}
		}
		WritableWorkbook workbook  =  Workbook.createWorkbook (fileName,book);
		WritableSheet sheet1 = workbook.getSheet(0); 
		Label label1 = new Label(0,len,conName);
		sheet1.addCell(label1);
		label1 = new Label(1,len,conClass);
		sheet1.addCell(label1);
		label1 = new Label(2,len,time);
		sheet1.addCell(label1);
		label1 = new Label(3,len,money);
		sheet1.addCell(label1);
		workbook.write(); 
		out.print("<script>alert('消费信息输入成功，再次输入');</script>");
		out.print("<script>window.location='inconinfo.jsp';</script>");
		workbook.close();			
		book.close(); 
	}catch(Exception e){
		out.print(e.getMessage());
	}


%>
